package jjn.carl.dp;

import java.util.Scanner;

/**
 * @author Jjn
 * @since 2023/8/22 21:45
 */
public class LeetCode198 {
    public int rob(int[] nums) {
        // dp[i] 到第i件物品，最大的价值
        int[] dp = new int[nums.length];
        dp[0] = Math.max(dp[0], dp[1]);
        for (int i = 2; i < nums.length; i++) {
            dp[i] = Math.max(dp[i - 1], dp[i - 2] + nums[i]);
        }
        return dp[nums.length - 1];
    }
    
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int count = scanner.nextInt();
        int[] nums = new int[count];
        for (int i = 0; i < nums.length; i++) {
            nums[i] = scanner.nextInt();
        }
        int robbed = new LeetCode198().rob(nums);
        System.out.println(robbed);
    }
}
